/**克隆工具 */
export default class CloneTools  {
   /**
    * 对像值转换-遍历赋值方式
    * @param old 旧对象
    * @param value 赋值新值
    */
    public static objectTransform<T>(old:T,value:T){
        for (const key in old) {
            old[key]=value[key];
        }
    }
     /**
     * 深度拷贝数据，
     * @param source 数据源
     * @returns 返回新数据
     */
	static deepCopy(source: Object): any {
		if (null == source || {} == source || [] == source) {
			return source;
		}
		let newObject: any;
		let isArray = false;
		if ((source as any).length) {
			newObject = [];
			isArray = true;
		}
		else {
			newObject = {};
			isArray = false;
		}

		for (let key of Object.keys(source)) {
			if (null == source[key]) {
				if (isArray) {
					newObject.push(null);
				}
				else {
					newObject[key] = null;
				}
			}
			else {
				let sub = (typeof source[key] == 'object') ? this.deepCopy(source[key]) : source[key];
				if (isArray) {
					newObject.push(sub);
				}
				else {
					newObject[key] = sub;
				}
			}
		}
		return newObject;
	}
}